<?php
$did = $_SESSION['memberID'];
$dtype = $_SESSION['dtype'];
if(!$did) {
    exit('未登录或登录超时！');
}
include '../common/autoload.php';
use \pft\notice;
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));

$action = $_REQUEST['action'];
switch($action){
	// 软终端验证发送验证码
	case 'sendTerVerify':
		if($_SESSION['useTer']==1){
			exit('{"reqState":"error","reqMsg":"您已经验证过，无需重新验证"}');
		}
		
		$sql="SELECT mobile FROM pft_member WHERE id=$did LIMIT 1";
		$GLOBALS['le']->query($sql);
		$GLOBALS['le']->fetch_assoc();
		$mobile = $GLOBALS['le']->f('mobile');
		if(!$mobile){
			echo '{"reqState":"error","reqMsg":"账号未绑定手机，请先绑定手机号"}';
			exit;
		}
		$time_diff = $_SERVER['REQUEST_TIME']-$_SESSION['terTimer'];
		if(isset($_SESSION['terTimer']) && $time_diff<60){
			 echo '{"reqState":"error","reqMsg":"发送间隔太短！请在60秒后再重试"}';
			 exit;
		}
		$_SESSION['terCode'] = mt_rand(100000,999999);
		$result = $s->Send_SMS_V($mobile,"您正在使用票付通票类验证，验证码{$_SESSION['terCode']}【票付通】");
		// $result = 100;
		if($result==100){
			$_SESSION['terTimer'] = $_SERVER['REQUEST_TIME'];
			echo '{"reqState":"success","reqMsg":"验证码已发送到手机，请验证"}';
			exit;
		}
		echo '{"reqState":"error","msg":"短信服务器发生故障。请联系我们客服人员","code":'.$result.'}';
		break;
	// 验证发送的验证码
	case 'verifyCode':
		$data = $_REQUEST['terCode'];
		if($data!=$_SESSION['terCode']){
			echo '{"reqState":"error","reqMsg":"验证码不正确"}';
			exit;
		}
		// 记录验证时间
		$sql="UPDATE pft_member_extinfo SET mobile_v_code=now() WHERE fid={$_SESSION['memberID']} LIMIT 1";
		$GLOBALS['le']->query($sql);
		$_SESSION['useTer'] = 1;
		echo '{"reqState":"success","reqMsg":"验证成功"}';
		break;
	
}

?>